package com.wx.web.controller.course;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eachonline.core.JsonResult;
import com.eachonline.core.Pagination;
import com.eachonline.util.StringUtil;
import com.wx.business.course.IxbBusinessPictureService;
import com.wx.business.course.IxbCourseCategoryService;
import com.wx.business.course.IxbCourseDetailService;
import com.wx.business.course.IxbCourseShareService;
import com.wx.business.course.IxbCourseVisitService;
import com.wx.business.course.IxbTrainingAgencyService;
import com.wx.business.util.IsActivity;
import com.wx.business.util.IsFinish;
import com.wx.business.util.IsOnline;
import com.wx.model.AppConfig;
import com.wx.model.IxbCourseDetailExample;
import com.wx.model.IxbCourseVisit;
import com.wx.model.IxbCourseVisitExample;
import com.wx.model.IxbTrainingAgency;
import com.wx.model.base.BaseIxbCourseDetailExample.Criteria;

/**
 * 课程管理控制器
 *
 * @author wemo
 * @Date 2018-08-08 18:27:50
 */
@Controller
@RequestMapping("/agency")
public class CourseTrainingAgencyController {


    @Autowired
    private IxbTrainingAgencyService   agencyService;
    
    
     /**
      * 查询机构详情
      * @param sid
      * @return
      */
    @RequestMapping(value = "/detail")
    @ResponseBody
    public JsonResult agencyDetail(String sid) {

    	if(StringUtil.isEmpty(sid))
    	{
    		return new JsonResult(false,"机构Id为空");
    	}
    		
    	IxbTrainingAgency agency=agencyService.selectByPrimaryKey(sid);
    	
    	Map<String,Object> dataMap=new HashMap<String, Object>();
    	dataMap.put("agency", agency);
    	
		return new JsonResult(true,dataMap);
    
    }
    
     /**
      * 机构课程列表
      * @param agencyId
      * @param courseType  1所有  2 活动  3 上新
      * @return
      */
   @RequestMapping(value = "/agencyCourseList")
   @ResponseBody
   public JsonResult agencyCourseList(String agencyId,int courseType) {
     Map<String,Object> dataMap=new HashMap<String, Object>();
   	if(StringUtil.isEmpty(agencyId))
   	{
   		return new JsonResult(false,"机构Id为空");
   	}
   		
	if(StringUtil.isEmpty(courseType+""))
   	{
   		return new JsonResult(false,"courseType课程类型不能为空");
   	}

	
	List<Map<String,Object>> courseList=agencyService.selectAgencyCourseList(courseType, agencyId);
	for (Map<String,Object> map:courseList) {
        map.put("businessPic", AppConfig.BaseUrl+map.get("businessPic"));
	}
	dataMap.put("courseList", courseList);
	return new JsonResult(true,dataMap);
	

   
   
   }
   
   
    
}
